package cn.netjava.softkid.chapter15;

import org.apache.commons.mail.EmailAttachment;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;

public class MailSender2 {


	public void send()
	{
		MultiPartEmail email = new MultiPartEmail();
		EmailAttachment attach = new EmailAttachment();
		email.setAuthentication("limeiyu520", "hnsfdxrjgc");
		email.setHostName("smtp.126.com");
		email.setSmtpPort(25);
		email.setSubject("my second javaMail!");
		
		attach.setName("PortScanner.java");
		attach.setPath("C:\\Documents and Settings\\Administrator\\My Documents\\PortScanner.java");
		attach.setDisposition(EmailAttachment.ATTACHMENT);
		attach.setDescription("hello");
		try {
			email.setFrom("limeiyu520@126.com");
			email.addTo("lin_hao_007@163.com");
			email.setContent("Hello,SB!", "text/plain;charset=GBK");
			email.attach(attach);
			email.send();
		} catch (EmailException e) {
			e.printStackTrace();
		}
		
		System.out.println("Already send to destination address......");
	}
	public static void main(String[] args) 
	{
		new MailSender2().send();
	}

}
